package com.ocl.www.controller;

import com.ocl.www.domain.BgPic;
import com.ocl.www.service.BgPicService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * Created by Administrator on 2016/12/9.
 */

@RestController
@RequestMapping("/bgPic")
public class BgPicController {
    @Autowired
    private BgPicService bgPicService;

    private Logger log = Logger.getLogger(BgPicController.class);
    @ResponseBody
    @RequestMapping(value = "/queryBgUrlWithIsUse", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value="查询背景图", notes="查询指定的最新的背景图")
    @ApiImplicitParam(name = "maptemp", value = "使用此格式：{}", required = true, dataType = "java.util.Map")
    public Map<String,Object> queryBgUrlWithIsUse(@RequestBody Map<String,Object> maptemp){
        BgPic bgPic = null;
        try {
            bgPic = bgPicService.queryBgUrlWithIsUse();
            maptemp.put("info","s");
            maptemp.put("bgPic",bgPic);
        } catch (Exception e) {
            maptemp.put("info","e");
            maptemp.put("tip",e.getMessage());
            log.info(e.getMessage());
            //e.printStackTrace();
        }
        //maptemp.put("bgPic",bgPic);
        return maptemp;
    }



    @ResponseBody
    @RequestMapping(value = "/queryPicForAdver", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value="查询顶部宣传图", notes="查询指定的最新的顶部宣传图")
    @ApiImplicitParam(name = "maptemp", value = "使用此格式：{}", required = true, dataType = "java.util.Map")
    public Map<String,Object> queryPicForAdver(@RequestBody Map<String,Object> maptemp){
        BgPic bgPic = null;
        try {
            bgPic = bgPicService.queryPicForAdver();
            maptemp.put("info","s");
            maptemp.put("bgPic",bgPic);
        } catch (Exception e) {
            maptemp.put("info","e");
            maptemp.put("tip",e.getMessage());
            log.info(e.getMessage());
            //e.printStackTrace();
        }
        //maptemp.put("bgPic",bgPic);
        return maptemp;
    }


    @ResponseBody
    @RequestMapping(value = "/deleteTopPic", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value="删除顶部宣传图", notes="删除指定的最新的顶部宣传图")
    @ApiImplicitParam(name = "maptemp", value = "使用此格式：{id:1}", required = true, dataType = "java.util.Map")
    public Map<String,Object> deleteTopPic(@RequestBody Map<String,Object> maptemp){
        BgPic bgPic = new BgPic();
        bgPic.setId(Integer.parseInt(maptemp.get("id").toString()));
        int c = 0;
        try {
            c = bgPicService.deleteTopPic(bgPic);
            maptemp.put("info","s");
            maptemp.put("bgPic",c);
        } catch (Exception e) {
            maptemp.put("info","e");
            maptemp.put("tip",e.getMessage());
            log.info(e.getMessage());
            //e.printStackTrace();
        }
        //maptemp.put("bgPic",bgPic);
        return maptemp;
    }

}
